<?php

namespace app\admin\model\csminvite;

use think\Model;


class Notify extends Model
{

    

    

    // 表名
    protected $name = 'csminvite_notify';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'notifyway_text',
        'effectbegintime_text',
        'effectendtime_text',
        'status_text'
    ];
    

    
    public function getNotifywayList()
    {
        return ['email' => __('Notifyway email'),'mobile' => __('Notifyway mobile')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getNotifywayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['notifyway']) ? $data['notifyway'] : '');
        $list = $this->getNotifywayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getEffectbegintimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['effectbegintime']) ? $data['effectbegintime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEffectendtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['effectendtime']) ? $data['effectendtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setEffectbegintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEffectendtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
